//
//  NetWorkTestViewController.m
//  CPICApp
//
//  Created by sinosoft on 13-3-22.
//  Copyright (c) 2013年 lizhiwei. All rights reserved.
//

#import "NetWorkTestViewController.h"
#import "RCAlertViewUtil.h"
#import "Config.h"
#import "RCAlertViewUtil.h"
#import "NSString+SBJson.h"
#import "NSObject+SBJson.h"
#import "MYPoint.h"
#import "UIImageView+WebCache.h"
#import "IFServiceEvaluation.h"
#import "WSqlite.h"
#import "PreferentialInformationViewController.h"
#import "TKAlertCenter.h"

@interface NetWorkTestViewController ()

@end

@implementation NetWorkTestViewController
@synthesize poiArray,progress,currentState;
@synthesize lblCarBrand,lblProduct,lblServiceType;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
-(void)viewDidAppear:(BOOL)animated{
    
    mamapView.mapType=MAMapTypeStandard;
    [self.view addSubview:mamapView];
    
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSString *bgimage= [accountDefaults objectForKey:@"UserDefaultBgKindKey"];
    
    
    if ([bgimage isEqualToString:@"蓝色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88@2x.png");
        ADD_LEFT_BUTTONITEM(@"back.png");
        ADD_TITLE_NAMEITEM(@"服务网点查询");
        ADD_EXCHANGEHISTORY_BUTTONITEM(@"RefreshDB.png");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    else if([bgimage isEqualToString:@"棕色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88_01@2x.png");
        ADD_LEFT_BUTTONITEM(@"back_01.png");
        ADD_TITLE_NAMEITEM(@"服务网点查询");
        ADD_EXCHANGEHISTORY_BUTTONITEM(@"RefreshDB.png");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773_01@2x"]];
    }
    else if([bgimage isEqualToString:@"重大节日皮肤"])
    {
        NSData *dataImg_02=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_02];
        NSLog(@"-------找到%@",dataImg_02);
        NSData *dataImg_03=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_03];
        NSData *dataImg_04=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_04];
        
        NSURL *urlSkinImg_02=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_02]];
        NSURL *urlSkinImg_03=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_03]];
        NSURL *urlSkinImg_04=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_04]];
        NSLog(@"-------找到333%@",urlSkinImg_02);
        
        UIImageView * LogoImage = [[UIImageView alloc]init];
        [LogoImage setImageWithURL:urlSkinImg_03 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(LogoImage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_03];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        LogoImage.image = [UIImage imageWithData:dataImg_03];
        LogoImage.frame = CGRectMake(0, 0, LogoImage.image.size.width/2, LogoImage.image.size.height/2);
        [self.view addSubview:LogoImage];
        
        //--------------------------
        UIButton * CallOutBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        CallOutBtn1.frame = CGRectMake(10, 10, 109/2, 57/2);
        UIImageView * Back = [[UIImageView alloc]init];
        [Back setImageWithURL:urlSkinImg_02 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(Back.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_02];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [Back setImage:[UIImage imageWithData:dataImg_02]];
        [CallOutBtn1 setImage:Back.image forState:UIControlStateNormal];
        [CallOutBtn1 addTarget:self action:@selector(ClickCallOutBtn) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:CallOutBtn1];
        //--------------------------
        
        ADD_TITLE_NAMEITEM(@"服务网点查询");
        
        UIImageView *bgimage = [[UIImageView alloc]initWithFrame:CGRectMake(0,44, self.view.frame.size.width, self.view.frame.size.height-44)];
        [bgimage setImageWithURL:urlSkinImg_04 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(bgimage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_04];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [bgimage setImage:[UIImage imageWithData:dataImg_04]];
        [self.view addSubview:bgimage];
        [bgimage release];
        ADD_EXCHANGEHISTORY_BUTTONITEM(@"RefreshDB.png");
    }
    
    
    //网络状态监测
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reachabilityChanged:)
                                                 name: kReachabilityChangedNotification
                                               object: nil];
    hostReach = [[Reachability reachabilityWithHostName:@"www.baidu.com"] retain];
    [hostReach startNotifier];
    //end

    arrServiceTypeAnotion=[[NSMutableArray alloc]init];
    arrProduct=[[NSMutableArray alloc]init];
    arrProductCode=[[NSMutableArray alloc]init];
    arrCarBrand=[[NSMutableArray alloc]init];
    arrCarBrandCode=[[NSMutableArray alloc]init];
    arrServiceTypeCode=[[NSMutableArray alloc]init];
    arrServiceName=[[NSMutableArray alloc]init];
    
    lblServiceType=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 270, 28)];
    lblServiceType.font=[UIFont boldSystemFontOfSize:13.0];
    lblServiceType.backgroundColor=[UIColor clearColor];
    lblServiceType.text=@"服务网点类型:";
    lblProduct=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 270, 28)];
    lblProduct.font=[UIFont boldSystemFontOfSize:13.0];
    lblProduct.backgroundColor=[UIColor clearColor];
    lblCarBrand=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 270, 28)];
    lblCarBrand.font=[UIFont boldSystemFontOfSize:13.0];
    lblCarBrand.backgroundColor=[UIColor clearColor];
    lblProduct.text=@"生产厂商";
    lblCarBrand.text=@"车辆品牌";
    NetWorkTag=0;
    TableCar=YES;
}

// 通知网络状态
- (void)reachabilityChanged:(NSNotification *)note {
    Reachability* curReach = [note object];
    NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
    currentState = [curReach currentReachabilityStatus];
    
    if (currentState == NotReachable)
    {

        [[WSqlite Instance] init];
        
        ISNETVALID=NO;
        AnotionViewDetail=[[UIView alloc]initWithFrame:CGRectMake(-10, -110, 250, 100)];
        AnotionViewDetail.backgroundColor=[UIColor blackColor];
        
        
        btnContent=[UIButton buttonWithType:UIButtonTypeCustom];
        btnContent.frame=CGRectMake(0, -8, 250, 40);
        btnContent.backgroundColor=[UIColor clearColor];
        btnContent.titleLabel.font=[UIFont systemFontOfSize:11.0];
        [btnContent setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btnContent addTarget:self action:@selector(gotoURL) forControlEvents:UIControlEventAllEvents];
        //[btnContent setTitle:@"新闻大厦 推荐指数7" forState:UIControlStateNormal];
        
        txwContentDetail=[[UITextView alloc]initWithFrame:CGRectMake(0, 20, 250, 100)];
        txwContentDetail.backgroundColor=[UIColor clearColor];
        txwContentDetail.textColor=[UIColor whiteColor];
        //txwContentDetail.text=@"详情详情详情详情详情详情详情详情详情详情详情详情详情详情详情详情详情详情详情详情,wwww.baidu.com";
        [AnotionViewDetail addSubview:btnContent];
        [AnotionViewDetail addSubview:txwContentDetail];
        //end
        
        mamapView=[[MAMapView alloc]initWithFrame:CGRectMake(0,138, 320,470)];
        mamapView.mapType = MAMapTypeStandard;
        mamapView.delegate=self;
        mamapView.showsUserLocation=YES;
        mamapView.showTraffic = NO;
        annotions=[[NSMutableArray alloc] init];
        isLocation=NO;
        [self.view addSubview:mamapView];
        
        
        //[self setManufactureRequest];
        //添加UITableview
        TableViewMap = [[UITableView alloc]initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, 94) style:UITableViewStyleGrouped];
        TableViewMap.delegate = self;
        TableViewMap.dataSource = self;
        
        TableViewMap.opaque = NO;
        TableViewMap.backgroundView = nil;
        TableViewMap.autoresizingMask = UIViewContentModeTop;
        TableViewMap.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
        TableViewMap.scrollEnabled=NO;
        TableViewMap.sectionFooterHeight=2;
        TableViewMap.sectionHeaderHeight=2;
        [self.view addSubview:TableViewMap];
        
        lblServiceType.text=@"服务网点类型:   4S维修保养店";
        strServiceType=@"OT_1001";
        NetWorkTag=NetWorkTag+1;
        if (NetWorkTag==1) {
            [NSThread detachNewThreadSelector:@selector(setRequest) toTarget:self withObject:nil];
        }
        
        
    }
    else
    {
        
        ISNETVALID=YES;
        AnotionViewDetail=[[UIView alloc]initWithFrame:CGRectMake(-10, -110, 250, 100)];
        AnotionViewDetail.backgroundColor=[UIColor blackColor];
        

        btnContent=[UIButton buttonWithType:UIButtonTypeCustom];
        btnContent.frame=CGRectMake(0, -8, 250, 40);
        btnContent.backgroundColor=[UIColor clearColor];
        btnContent.titleLabel.font=[UIFont systemFontOfSize:11.0];
        [btnContent setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btnContent addTarget:self action:@selector(gotoURL) forControlEvents:UIControlEventAllEvents];
        //[btnContent setTitle:@"新闻大厦 推荐指数7" forState:UIControlStateNormal];
        
        txwContentDetail=[[UITextView alloc]initWithFrame:CGRectMake(0, 20, 250, 100)];
        txwContentDetail.backgroundColor=[UIColor clearColor];
        txwContentDetail.textColor=[UIColor whiteColor];
        //txwContentDetail.text=@"详情详情详情详情详情详情详情详情详情详情详情详情详情详情详情详情详情详情详情详情,wwww.baidu.com";
        [AnotionViewDetail addSubview:btnContent];
        [AnotionViewDetail addSubview:txwContentDetail];
        //end
        
        lblServiceType.text=@"服务网点类型:4S维修保养点";
        lblCarBrand.text=@"生产厂商:";
        
        mamapView=[[MAMapView alloc]initWithFrame:CGRectMake(0,138, 320,470)];
        mamapView.mapType = MAMapTypeStandard;
        mamapView.delegate=self;
        mamapView.showsUserLocation=YES;
        mamapView.showTraffic = NO;
        annotions=[[NSMutableArray alloc] init];
        isLocation=NO;
        [self.view addSubview:mamapView];
        
        
        //[self setManufactureRequest];
        //添加UITableview
        TableViewMap = [[UITableView alloc]initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, 94) style:UITableViewStyleGrouped];
        TableViewMap.delegate = self;
        TableViewMap.dataSource = self;
        
        TableViewMap.opaque = NO;
        TableViewMap.backgroundView = nil;
        TableViewMap.autoresizingMask = UIViewContentModeTop;
        TableViewMap.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
        TableViewMap.scrollEnabled=NO;
        TableViewMap.sectionFooterHeight=2;
        TableViewMap.sectionHeaderHeight=2;
        [self.view addSubview:TableViewMap];
        
        strServiceType=@"OT_1001";
        NetWorkTag=NetWorkTag+1;
        if (NetWorkTag==1) {

             [NSThread detachNewThreadSelector:@selector(getCarInfo) toTarget:self withObject:nil];
            [self setEvaluationRequest];
            [self setServiceTypeRequestInit];
    
            //[self setRequest];
        }
        
//        [self setManufactureRequest];
//          [self setServiceTypeRequest];
    }
}
-(void)ClickExchangeHistoryBtn
{
    NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
    if (strServiceType.length==0) {
        [self justShowMessage:@"服务网点类型为空" title:@"注意"];
        return;
    }
    [dicRequest setObject:strServiceType forKey:@"serverType"];
    if (strCarBrandddd.length!=0) {
        [dicRequest setObject:strCarBrandddd forKey:@"brand"];
    }
    else
    {
        [dicRequest setObject:@"" forKey:@"brand"];
        
    }
    
    [dicRequest setObject:@"" forKey:@"userAccount"];
    NSString *strRequestJson=[dicRequest JSONRepresentation];
    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
    
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [request setPostValue:@"50101" forKey:@"RequestCode"];
    [request setPostValue:strRequestJson forKey:@"RequestData"];
    
    [request setDelegate:self];
    [request setDidFailSelector:@selector(ResponseFail:)];
    [request setDidFinishSelector:@selector(ResonseSuccess:)];
    [request startAsynchronous];
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 耗时的操作
        dispatch_async(dispatch_get_main_queue(), ^{
            // 更新界面
            
            showProgress = YES;
            if (showProgress) {
                NSLog(@"88888");
                //[NSThread sleepForTimeInterval:1];
                progress= [[MBProgressHUD alloc]initWithView:self.navigationController.view];
                [self.navigationController.view addSubview:progress];
                [self.navigationController.view bringSubviewToFront:progress];
                progress.labelText = @"查询中...";
                [progress show:YES];
                showProgress = NO;
            };
        });
    });

}
-(void)gotoURL:(id)sender
{

        if (strURLLLLLL.length==0) {
            [self justShowMessage:@"网页地址为空" title:@"注意"];
            return;
        }
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strURLLLLLL]];

}
-(void)sendPhoneno:(id)sender
{
    if (strPhoneeeee.length==0) {
        [self justShowMessage:@"电话号码为空" title:@"注意"];
        return;
    }

    UIWebView*callWebview =[[UIWebView alloc] init];
    NSURL *telURL =[NSURL URLWithString:strPhoneeeee];
    [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
    [self.view addSubview:callWebview];
}
-(void)gotoPreferential:(id)sender
{
    UIButton *myPoint=(UIButton *)sender;
    NSMutableDictionary *dictItem=[arrData objectAtIndex:myPoint.tag];
    strid=[dictItem valueForKey:@"id"];
    PreferentialInformationViewController *preferentialInformationViewCtrl=[[PreferentialInformationViewController alloc]init];
    preferentialInformationViewCtrl.strServerType=strServiceType;
    preferentialInformationViewCtrl.strservicepoint=strid;

    [self.navigationController pushViewController:preferentialInformationViewCtrl animated:YES];
    [preferentialInformationViewCtrl release];
    
}

-(void)getCarInfo
{
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil)
    {
        if ([dictUserInfo valueForKey:@"UserAccount"])
        {
            NSString *strUserAccount=[dictUserInfo valueForKey:@"UserAccount"];
            if (strUserAccount.length!=0) {
                RCCarListInfo *rcCarListInfo=[[RCCarListInfo alloc]initCarListInfoView];
                rcCarListInfo.carInfoDelegate=self;
                [rcCarListInfo setCarListRequest:NO];
                [rcCarListInfo setHidden:YES];
                [self.view addSubview:rcCarListInfo];
                [rcCarListInfo release];
            }
            else
            {
                [self setRequest];
            }
        }
        else
        {
            [self setRequest];
        }
    }
    else
    {
        [self setRequest];
    }
}
-(void)getCarListInfo:(BOOL)bCarInfo
{
    
}
-(void)getCarDetailInfo
{
    NSUserDefaults *myDefaultsCarInfo=[NSUserDefaults standardUserDefaults];
    NSDictionary *dictCarInfo=[myDefaultsCarInfo dictionaryForKey:DICT_CAR_CUSTOMERINFO];
    if (dictCarInfo!=nil)
    {
        if ([dictCarInfo valueForKey:@"brand"])
        {
            strCarViewBrand=[dictCarInfo valueForKey:@"brand"];

        }
        else
        {
            strCarViewBrand=@"";
        }
        
    if ([dictCarInfo valueForKey:@"manufacturersName"]) {
        lblProduct.text=[NSString stringWithFormat:@"生产厂商:%@",[dictCarInfo valueForKey:@"manufacturersName"]];
        strManufacturerName=[dictCarInfo valueForKey:@"manufacturersName"];
    }
    
    if ([dictCarInfo valueForKey:@"brandName"]) {
        lblCarBrand.text=[NSString stringWithFormat:@"车辆品牌:%@",[dictCarInfo valueForKey:@"brandName"]];
        strBrandName=[dictCarInfo valueForKey:@"brandName"];
    }
   
    }
    else
    {
        strCarViewBrand=@"";
    }
    strCarBrandddd=strCarViewBrand;
    
    if (strBrandName.length==0) {
        [[TKAlertCenter defaultCenter] postAlertWithMessage:@"请设置车辆厂商和品牌信息"];
    }
    if (strBrandName.length==0) {
        strCarBrandddd=@"";
        strCarViewBrand=@"";
    }
    if (strCarBrandddd.length==0) {
        lblProduct.text=@"生产厂商:所有";
        lblCarBrand.text=@"车辆品牌";
    }
    else
    {
        lblProduct.text=[NSString stringWithFormat:@"生产厂商:%@",[dictCarInfo valueForKey:@"manufacturersName"]];
        lblCarBrand.text=[NSString stringWithFormat:@"车辆品牌:%@",[dictCarInfo valueForKey:@"brandName"]];
    }
    
    [TableViewMap reloadData];
   [self setRequest];

}
-(void)setRequest//向太保移动平台发送请求报文
{
    NSLog(@"123456");
    if (strCarBrandddd.length==0) {
        lblProduct.text=@"生产厂商:所有";
        lblCarBrand.text=@"车辆品牌";
    }
    //[TableViewMap reloadData];
    if (ISNETVALID==YES) {
        //    NSString *strRequestCode=@"RequestCode=50101";
        
        if ([arrData count]>0) {
            [arrData removeAllObjects];
        }
        WSqlite *sql =[WSqlite Instance];
        //arrData=[sql getServiceSpecifyPoint:strServiceType];
        //arrData=[sql getServiceSpecifyPoint2:strServiceType withBrand:strCarBrandddd];
        arrData=[sql getServiceBrandPoint:strServiceType withBrand:strCarBrandddd];
        if ([arrData count]>0) {
            
            
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                // 耗时的操作
                dispatch_async(dispatch_get_main_queue(), ^{
                    // 更新界面
                    
                    showProgress = YES;
                    if (showProgress) {
                        NSLog(@"88888");
                        //[NSThread sleepForTimeInterval:1];
                        progress= [[MBProgressHUD alloc]initWithView:self.navigationController.view];
                        [self.navigationController.view addSubview:progress];
                        [self.navigationController.view bringSubviewToFront:progress];
                        progress.labelText = @"查询中...";
                        [progress show:YES];
                        showProgress = NO;
                    };
                });
            });
            

            
            if ([arrServiceTypeAnotion count]>0) {
                [mamapView removeAnnotations:arrServiceTypeAnotion];
                [arrServiceTypeAnotion removeAllObjects];
            }
            for (int i=0; i<[arrData count]; i++) {
                NSMutableDictionary *dictItem=[arrData objectAtIndex:i];
                NSString *strAddress=[dictItem valueForKey:@"position"];
                NSArray *arrayAddress=[strAddress componentsSeparatedByString:@","];
                if ([arrayAddress count]<2) {
                    continue;
                }
                NSString *strDimension=[arrayAddress objectAtIndex:0];//维度
                NSString *strLongitude=[arrayAddress objectAtIndex:1];//经度
                double Dimension=strDimension.doubleValue;
                double Longitude=strLongitude.doubleValue;
                MYPoint *pointAnn = [[[MYPoint alloc]init]autorelease];
                pointAnn.tag=i;
                pointAnn.coordinate=CLLocationCoordinate2DMake(Dimension,Longitude);
                
                [arrServiceTypeAnotion addObject:pointAnn];
                
            }
            
            
            if ([arrServiceTypeAnotion count]>0) {
                //[self performSelectorOnMainThread:@selector(mainThreadAddAnotion) withObject:nil waitUntilDone:NO];
//                [mamapView addAnnotations:arrServiceTypeAnotion];
                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                    // 耗时的操作
                    dispatch_async(dispatch_get_main_queue(), ^{
                        // 更新界面
                        
                        [mamapView addAnnotations:arrServiceTypeAnotion];
                        
                        if (!showProgress)
                        {
                            [progress removeFromSuperview];
                            progress = nil;
                        }
                        
                        [TableViewMap reloadData];
                        
                    });
                });
            }
            


        }
        else
        {
            NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
            if (strServiceType.length==0) {
                [self justShowMessage:@"服务网点类型为空" title:@"注意"];
                return;
            }
            [dicRequest setObject:strServiceType forKey:@"serverType"];
            if (strCarBrandddd.length!=0) {
                [dicRequest setObject:strCarBrandddd forKey:@"brand"];
            }
            else
            {
                if ([strServiceType isEqualToString:@"OT_1001"])
                {
                    if (strBrandInvalid.length!=0)
                    {
                        if (strCarViewBrand.length==0)
                        {
                            [dicRequest setObject:@"" forKey:@"brand"];
                        }
                        else
                        {
                            [dicRequest setObject:strCarViewBrand forKey:@"brand"];
                        }
                    }
                    else
                    {
                        if (strCarViewBrand.length==0)
                        {
                            [dicRequest setObject:@"" forKey:@"brand"];
                        }
                        else
                        {
                            [dicRequest setObject:strCarViewBrand forKey:@"brand"];
                        }
                    }
                }
                else
                {
                    [dicRequest setObject:@"" forKey:@"brand"];
                }
                
                
            }
            
            [dicRequest setObject:@"" forKey:@"userAccount"];
            NSString *strRequestJson=[dicRequest JSONRepresentation];
            ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
            
            //设置需要POST的数据，这里提交两个数据，A=a&B=b
            [request setPostValue:@"50101" forKey:@"RequestCode"];
            [request setPostValue:strRequestJson forKey:@"RequestData"];
            
            [request setDelegate:self];
            [request setDidFailSelector:@selector(ResponseFail:)];
            [request setDidFinishSelector:@selector(ResonseSuccess:)];
            [request startAsynchronous];
            
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                // 耗时的操作
                dispatch_async(dispatch_get_main_queue(), ^{
                    // 更新界面
                    
                    showProgress = YES;
                    if (showProgress) {
                        NSLog(@"88888");
                        //[NSThread sleepForTimeInterval:1];
                        progress= [[MBProgressHUD alloc]initWithView:self.navigationController.view];
                        [self.navigationController.view addSubview:progress];
                        [self.navigationController.view bringSubviewToFront:progress];
                        progress.labelText = @"查询中...";
                        [progress show:YES];
                        showProgress = NO;
                    };
                });
            });
        }
        
        
    }
    else if(ISNETVALID==NO)
    {
        //[NSThread detachNewThreadSelector:@selector(NetWorkValidAddAnomation) toTarget:self withObject:nil];
        [self NetWorkValidAddAnomation];
    }
    else
    {
        
    }

    
    
}

-(void)NetWorkValidAddAnomation
{
    if ([arrData count]>0) {
        [arrData removeAllObjects];
    }
    [self performSelectorOnMainThread:@selector(mainThreadRemoveAotion) withObject:nil waitUntilDone:YES];
    
//    dispatch_async(dispatch_get_main_queue(), ^{
//        // 更新界面
//        if ([arrServiceTypeAnotion count]>0) {
//            [mamapView removeAnnotations:arrServiceTypeAnotion];
//            [arrServiceTypeAnotion removeAllObjects];
//        }
//        showProgress = YES;
//        if (showProgress) {
//            NSLog(@"88888");
//            //[NSThread sleepForTimeInterval:1];
//            progress= [[MBProgressHUD alloc]initWithView:self.view];
//            [self.view addSubview:progress];
//            [self.view bringSubviewToFront:progress];
//            progress.labelText = @"查询中...";
//            [progress show:YES];
//            showProgress = NO;
//        };
//        
//    });
//
//    if ([arrData count]>0) {
//        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//            // 耗时的操作
//            dispatch_async(dispatch_get_main_queue(), ^{
//                // 更新界面
//                
//                showProgress = YES;
//                if (showProgress) {
//                    NSLog(@"88888");
//                    //[NSThread sleepForTimeInterval:1];
//                    progress= [[MBProgressHUD alloc]initWithView:self.view];
//                    [self.view addSubview:progress];
//                    [self.view bringSubviewToFront:progress];
//                    progress.labelText = @"查询中...";
//                    [progress show:YES];
//                    showProgress = NO;
//                };
//            });
//        });
//    }

    //if ([arrServiceTypeAnotion count]>0) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            // 耗时的操作
            WSqlite *sql =[WSqlite Instance];
            //arrData=[sql getServiceSpecifyPoint2:strServiceType withBrand:strCarBrandddd];
            arrData=[sql getServiceBrandPoint:strServiceType withBrand:strCarBrandddd];
            
            for (int i=0; i<[arrData count]; i++) {
                NSMutableDictionary *dictItem=[arrData objectAtIndex:i];
                NSString *strAddress=[dictItem valueForKey:@"position"];
                NSArray *arrayAddress=[strAddress componentsSeparatedByString:@","];
                if ([arrayAddress count]<2) {
                    continue;
                }
                NSString *strDimension=[arrayAddress objectAtIndex:0];//维度
                NSString *strLongitude=[arrayAddress objectAtIndex:1];//经度
                double Dimension=strDimension.doubleValue;
                double Longitude=strLongitude.doubleValue;
                MYPoint *pointAnn = [[[MYPoint alloc]init]autorelease];
                pointAnn.tag=i;
                pointAnn.coordinate=CLLocationCoordinate2DMake(Dimension,Longitude);
                
                [arrServiceTypeAnotion addObject:pointAnn];
                
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                // 更新界面
                NSLog(@"arrServiceTypeAnotion:%@",arrServiceTypeAnotion);
                [mamapView addAnnotations:arrServiceTypeAnotion];
                
                if (!showProgress)
                {
                    [progress removeFromSuperview];
                    progress = nil;
                }
                [TableViewMap reloadData];
            });
        });
   // }

}

-(void)mainThreadRemoveAotion
{
    if ([arrServiceTypeAnotion count]>0) {
        [mamapView removeAnnotations:arrServiceTypeAnotion];
        [arrServiceTypeAnotion removeAllObjects];
    }
    showProgress = YES;
    if (showProgress) {
        NSLog(@"88888");
        //[NSThread sleepForTimeInterval:1];
        progress= [[MBProgressHUD alloc]initWithView:self.view];
        [self.view addSubview:progress];
        [self.view bringSubviewToFront:progress];
        progress.labelText = @"查询中...";
        [progress show:YES];
        showProgress = NO;
    };
}

-(void)mainThreadAddAnotion
{
    [mamapView addAnnotations:arrServiceTypeAnotion];
}
- (void)ResonseSuccess:(ASIHTTPRequest *)request
{
    Flag = @"0";
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 耗时的操作
        dispatch_async(dispatch_get_main_queue(), ^{
            // 更新界面
            
            if (!showProgress)
            {
                [progress removeFromSuperview];
                progress = nil;
            }
        });
    });
    [TableViewMap reloadData];
    if ([arrServiceTypeAnotion count]>0) {
        [mamapView removeAnnotations:arrServiceTypeAnotion];
        [arrServiceTypeAnotion removeAllObjects];
    }
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse  %@",dictResponse);
    NSMutableDictionary *dictServicePointList=[dictResponse objectForKey:@"servicePointList"];
    arrData=[dictServicePointList objectForKey:@"data"];
    
    //if (strCarBrandddd.length==0) {
         [NSThread detachNewThreadSelector:@selector(updateDatabase) toTarget:self withObject:nil];
   // }
    
    for (int i=0; i<[arrData count]; i++) {
        NSMutableDictionary *dictItem=[arrData objectAtIndex:i];
        NSString *strAddress=[dictItem valueForKey:@"position"];
        NSArray *arrayAddress=[strAddress componentsSeparatedByString:@","];
        if ([arrayAddress count]<2) {
            continue;
        }
        NSString *strDimension=[arrayAddress objectAtIndex:0];//维度
        NSString *strLongitude=[arrayAddress objectAtIndex:1];//经度
        double Dimension=strDimension.doubleValue;
        double Longitude=strLongitude.doubleValue;
        MYPoint *pointAnn = [[[MYPoint alloc]init]autorelease];
        pointAnn.tag=i;
        pointAnn.coordinate=CLLocationCoordinate2DMake(Dimension,Longitude);

        [arrServiceTypeAnotion addObject:pointAnn];

    }
    if ([arrServiceTypeAnotion count]>0) {
        [mamapView addAnnotations:arrServiceTypeAnotion];
    }
}
-(void)updateDatabase
{
    WSqlite *sql =[WSqlite Instance];
    //[sql insertServicePoint:arrData];
    [sql insertServicePoint:arrData brandCode:strCarBrandddd];
}
- (void)ResponseFail:(ASIHTTPRequest *)request
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 耗时的操作
        dispatch_async(dispatch_get_main_queue(), ^{
            // 更新界面
            
            if (!showProgress)
            {
                [progress removeFromSuperview];
                progress = nil;
            }
        });
    });
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败" title:@"注意"];
}

-(void)setServiceTypeRequestInit
{
    if (ISNETVALID==YES) {
        //    NSString *strRequestCode=@"RequestCode=50103";
        NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
        if ([myDefaults arrayForKey:ARRAY_NETPOINT_TYPE]) {
            NSMutableArray *myServiceTypeCode=[[NSMutableArray alloc]initWithArray:[myDefaults arrayForKey:ARRAY_NETPOINT_TYPE]];
            NSMutableArray *myServiceName=[[NSMutableArray alloc]initWithArray:[myDefaults arrayForKey:ARRAY_NETPOINT_NAME]];
            if (myServiceTypeCode.count!=0 && myServiceTypeCode!=nil) {
                arrServiceTypeCode=myServiceTypeCode;
                arrServiceName=myServiceName;
            }
        }
        
        if (arrServiceName.count>0) {
        }
        else
        {
            NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
            NSNumber *PageNo=[NSNumber numberWithInt:1];
            [dicRequest setObject:PageNo forKey:@"pageNo"];
            NSNumber *PageSize=[NSNumber numberWithInt:20];
            [dicRequest setObject:PageSize forKey:@"pageSize"];
            [dicRequest setObject:@"admin22" forKey:@"userAccount"];
            NSString *strRequestJson=[dicRequest JSONRepresentation];
            requestServerType = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
            
            //设置需要POST的数据，这里提交两个数据，A=a&B=b
            [requestServerType setPostValue:@"50103" forKey:@"RequestCode"];
            [requestServerType setPostValue:strRequestJson forKey:@"RequestData"];
            
            [requestServerType setDelegate:self];
            [requestServerType setDidFailSelector:@selector(ResponseServiceTypeInitFail:)];
            [requestServerType setDidFinishSelector:@selector(ResonseServiceTypeInitSuccess:)];
            [requestServerType startAsynchronous];
            
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                // 耗时的操作
                dispatch_async(dispatch_get_main_queue(), ^{
                    // 更新界面
                    
//                    showProgress = YES;
//                    if (showProgress) {
//                        NSLog(@"88888");
//                        //[NSThread sleepForTimeInterval:1];
//                        progress= [[MBProgressHUD alloc]initWithView:self.navigationController.view];
//                        [self.navigationController.view addSubview:progress];
//                        [self.navigationController.view bringSubviewToFront:progress];
//                        progress.labelText = @"查询中...";
//                        [progress show:YES];
//                        showProgress = NO;
//                    };
                });
            });
        }
        
    }

}

- (void)ResonseServiceTypeInitSuccess:(ASIHTTPRequest *)request
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 耗时的操作
        dispatch_async(dispatch_get_main_queue(), ^{
            // 更新界面
            
//            if (!showProgress)
//            {
//                [progress removeFromSuperview];
//                progress = nil;
//            }
        });
    });
    [arrServiceName removeAllObjects];
    [arrServiceTypeCode removeAllObjects];
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse  %@",dictResponse);
    NSMutableDictionary *dictPointTypeList=[dictResponse objectForKey:@"pointTypeList"];
    NSMutableArray *arrServiceData=[dictPointTypeList objectForKey:@"data"];
    for (int i=0; i<[arrServiceData count]; i++) {
        NSMutableDictionary *dictItem=[arrServiceData objectAtIndex:i];
        WSqlite *sql =[WSqlite Instance];
        [sql insertServiceType:[dictItem valueForKey:@"serverType"] serviceName:[dictItem valueForKey:@"name"]];
        
        if ([dictItem valueForKey:@"name"]) {
            NSString *strName=[dictItem valueForKey:@"name"];
            [arrServiceName addObject:strName];
        }
        if ([dictItem valueForKey:@"serverType"]) {
            NSString *strType=[dictItem valueForKey:@"serverType"];
            if ([strType isEqualToString:@"OT_1001"]) {
                if ([dictItem valueForKey:@"brand"]) {
                    strBrandInvalid=[dictItem valueForKey:@"brand"];
                }
                
            }
            [arrServiceTypeCode addObject:strType];
        }
    }
    
    NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
    [myDefaults setObject:arrServiceName forKey:ARRAY_NETPOINT_NAME];
    [myDefaults setObject:arrServiceTypeCode forKey:ARRAY_NETPOINT_TYPE];
    [myDefaults synchronize];
}

- (void)ResponseServiceTypeInitFail:(ASIHTTPRequest *)request
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 耗时的操作
        dispatch_async(dispatch_get_main_queue(), ^{
            // 更新界面
            
//            if (!showProgress)
//            {
//                [progress removeFromSuperview];
//                progress = nil;
//            }
        });
    });
    NSLog(@"服务器连接失败!");
}
-(void)setServiceTypeRequest//向太保移动平台发送请求报文
{
    if (ISNETVALID==YES) {
        //    NSString *strRequestCode=@"RequestCode=50103";
        NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
        if ([myDefaults arrayForKey:ARRAY_NETPOINT_TYPE]) {
            NSMutableArray *myServiceTypeCode=[[NSMutableArray alloc]initWithArray:[myDefaults arrayForKey:ARRAY_NETPOINT_TYPE]];
            NSMutableArray *myServiceName=[[NSMutableArray alloc]initWithArray:[myDefaults arrayForKey:ARRAY_NETPOINT_NAME]];
            if (myServiceTypeCode.count!=0 && myServiceTypeCode!=nil) {
                arrServiceTypeCode=myServiceTypeCode;
                arrServiceName=myServiceName;
            }
        }
        
        if (arrServiceName.count>0) {
            if (arrServiceName.count==0) {
                [self justShowMessage:@"服务网点类型为空" title:@"注意"];
                return;
            }
            CustomActionSheet *sheet=[[CustomActionSheet alloc]initWithHeight:284.0f WithSheetTitle:@"" WithDataArray:arrServiceName];
            sheet.tag=1;
            sheet.Customdelegate=self;
            [sheet showInView:self.view];
        }
        else
        {
            NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
            NSNumber *PageNo=[NSNumber numberWithInt:1];
            [dicRequest setObject:PageNo forKey:@"pageNo"];
            NSNumber *PageSize=[NSNumber numberWithInt:20];
            [dicRequest setObject:PageSize forKey:@"pageSize"];
            [dicRequest setObject:@"admin22" forKey:@"userAccount"];
            NSString *strRequestJson=[dicRequest JSONRepresentation];
            ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
            
            //设置需要POST的数据，这里提交两个数据，A=a&B=b
            [request setPostValue:@"50103" forKey:@"RequestCode"];
            [request setPostValue:strRequestJson forKey:@"RequestData"];
            
            [request setDelegate:self];
            [request setDidFailSelector:@selector(ResponseServiceTypeFail:)];
            [request setDidFinishSelector:@selector(ResonseServiceTypeSuccess:)];
            [request startAsynchronous];
            
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                // 耗时的操作
                dispatch_async(dispatch_get_main_queue(), ^{
                    // 更新界面
                    
                    showProgress = YES;
                    if (showProgress) {
                        NSLog(@"88888");
                        //[NSThread sleepForTimeInterval:1];
                        progress= [[MBProgressHUD alloc]initWithView:self.navigationController.view];
                        [self.navigationController.view addSubview:progress];
                        [self.navigationController.view bringSubviewToFront:progress];
                        progress.labelText = @"查询中...";
                        [progress show:YES];
                        showProgress = NO;
                    };
                });
            });
        }
        
    }
    else if(ISNETVALID==NO)
    {
        NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
        if ([myDefaults arrayForKey:ARRAY_NETPOINT_TYPE]) {
            NSMutableArray *myServiceTypeCode=[[NSMutableArray alloc]initWithArray:[myDefaults arrayForKey:ARRAY_NETPOINT_TYPE]];
            NSMutableArray *myServiceName=[[NSMutableArray alloc]initWithArray:[myDefaults arrayForKey:ARRAY_NETPOINT_NAME]];
            if (myServiceTypeCode.count!=0 && myServiceTypeCode!=nil) {
                arrServiceTypeCode=myServiceTypeCode;
                arrServiceName=myServiceName;
            }
        }
        
        if (arrServiceName.count==0) {
            [self justShowMessage:@"服务网点类型为空" title:@"注意"];
            return;
        }
        CustomActionSheet *sheet=[[CustomActionSheet alloc]initWithHeight:284.0f WithSheetTitle:@"" WithDataArray:arrServiceName];
        sheet.tag=1;
        sheet.Customdelegate=self;
        [sheet showInView:self.view];
    }

    
}

- (void)ResonseServiceTypeSuccess:(ASIHTTPRequest *)request
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 耗时的操作
        dispatch_async(dispatch_get_main_queue(), ^{
            // 更新界面
            
            if (!showProgress)
            {
                [progress removeFromSuperview];
                progress = nil;
            }
        });
    });
    [arrServiceName removeAllObjects];
    [arrServiceTypeCode removeAllObjects];
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse  %@",dictResponse);
    NSMutableDictionary *dictPointTypeList=[dictResponse objectForKey:@"pointTypeList"];
    NSMutableArray *arrServiceData=[dictPointTypeList objectForKey:@"data"];
    for (int i=0; i<[arrServiceData count]; i++) {
        NSMutableDictionary *dictItem=[arrServiceData objectAtIndex:i];
        WSqlite *sql =[WSqlite Instance];
        [sql insertServiceType:[dictItem valueForKey:@"serverType"] serviceName:[dictItem valueForKey:@"name"]];
        
        if ([dictItem valueForKey:@"name"]) {
            NSString *strName=[dictItem valueForKey:@"name"];
            [arrServiceName addObject:strName];
        }
        if ([dictItem valueForKey:@"serverType"]) {
            NSString *strType=[dictItem valueForKey:@"serverType"];
            if ([strType isEqualToString:@"OT_1001"]) {
                if ([dictItem valueForKey:@"brand"]) {
                     strBrandInvalid=[dictItem valueForKey:@"brand"];
                }
               
            }
            [arrServiceTypeCode addObject:strType];
        }
    }
    
    NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
    [myDefaults setObject:arrServiceName forKey:ARRAY_NETPOINT_NAME];
    [myDefaults setObject:arrServiceTypeCode forKey:ARRAY_NETPOINT_TYPE];
    [myDefaults synchronize];
    
    
    if ([arrServiceName count]==0) {
        [self justShowMessage:@"服务网点类型为空" title:@"注意"];
        return;
    }
    CustomActionSheet *sheet=[[CustomActionSheet alloc]initWithHeight:284.0f WithSheetTitle:@"" WithDataArray:arrServiceName];
    sheet.tag=1;
    sheet.Customdelegate=self;
    [sheet showInView:self.view];
}

- (void)ResponseServiceTypeFail:(ASIHTTPRequest *)request
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 耗时的操作
        dispatch_async(dispatch_get_main_queue(), ^{
            // 更新界面
            
            if (!showProgress)
            {
                [progress removeFromSuperview];
                progress = nil;
            }
        });
    });
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败" title:@"注意"];
}

-(void)setManufactureRequest//向太保移动平台发送请求报文
{
    WSqlite *sql =[WSqlite Instance];
    NSMutableArray *myArrData=[sql getManufacturer];
    if ([myArrData count]>0) {
        [arrProduct removeAllObjects];
        [arrProductCode removeAllObjects];
        for (int i=0; i<[myArrData count]; i++) {
            
            NSMutableDictionary *dictItem=[myArrData objectAtIndex:i];
            NSString *str=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"manufacturerName"]];
            NSString *strCode=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"manufacturerCode"]];
            [arrProduct addObject:str];
            [arrProductCode addObject:strCode];
        }
        [arrProduct insertObject:@"所有" atIndex:0];
        [arrProductCode insertObject:@"all" atIndex:0];
        
        if ([arrProduct count]==0) {
            [self justShowMessage:@"生产厂商为空" title:@"注意"];
            return;
        }
        CustomActionSheet *sheet=[[CustomActionSheet alloc]initWithHeight:284.0f WithSheetTitle:@"" WithDataArray:arrProduct];
        sheet.tag=2;
        sheet.Customdelegate=self;
        [sheet showInView:self.view];
        
    }
    else
    {
        
        NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
        [dicRequest setObject:@"admin22" forKey:@"userAccount"];
        NSString *strRequestJson=[dicRequest JSONRepresentation];
        ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
        
        //设置需要POST的数据，这里提交两个数据，A=a&B=b
        [request setPostValue:@"62011" forKey:@"RequestCode"];
        [request setPostValue:strRequestJson forKey:@"RequestData"];
        
        [request setDelegate:self];
        [request setDidFailSelector:@selector(ResponseManufactureFail:)];
        [request setDidFinishSelector:@selector(ResonseManufactureSuccess:)];
        [request startAsynchronous];
        
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            // 耗时的操作
            dispatch_async(dispatch_get_main_queue(), ^{
                // 更新界面
                
                showProgress = YES;
                if (showProgress) {
                    NSLog(@"88888");
                    //[NSThread sleepForTimeInterval:1];
                    progress= [[MBProgressHUD alloc]initWithView:self.navigationController.view];
                    [self.navigationController.view addSubview:progress];
                    [self.navigationController.view bringSubviewToFront:progress];
                    progress.labelText = @"查询中...";
                    [progress show:YES];
                    showProgress = NO;
                };
            });
        });
    }
}

- (void)ResonseManufactureSuccess:(ASIHTTPRequest *)request
{
    Flag=@"0";
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 耗时的操作
        dispatch_async(dispatch_get_main_queue(), ^{
            // 更新界面
            
            if (!showProgress)
            {
                [progress removeFromSuperview];
                progress = nil;
            }
        });
    });
    [arrProduct removeAllObjects];
    [arrProductCode removeAllObjects];
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse  %@",dictResponse);
    NSMutableArray *myArrData=[dictResponse valueForKey:@"datas"];
    if ([myArrData count]>0) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            // 耗时的操作
            WSqlite *sql =[WSqlite Instance];
            [sql insertManufacturer:myArrData];
            dispatch_async(dispatch_get_main_queue(), ^{
                // 更新界面
            });
        });
    }
    for (int i=0; i<[myArrData count]; i++) {
        
        NSMutableDictionary *dictItem=[myArrData objectAtIndex:i];
        NSString *str=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"manufacturerName"]];
        NSString *strCode=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"manufacturerCode"]];
        [arrProduct addObject:str];
        [arrProductCode addObject:strCode];
    }
    [arrProduct insertObject:@"所有" atIndex:0];
    [arrProductCode insertObject:@"all" atIndex:0];
    
    if ([arrProduct count]==0) {
        [self justShowMessage:@"生产厂商为空" title:@"注意"];
        return;
    }
    CustomActionSheet *sheet=[[CustomActionSheet alloc]initWithHeight:284.0f WithSheetTitle:@"" WithDataArray:arrProduct];
    sheet.tag=2;
    sheet.Customdelegate=self;
    [sheet showInView:self.view];
}

- (void)ResponseManufactureFail:(ASIHTTPRequest *)request
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 耗时的操作
        dispatch_async(dispatch_get_main_queue(), ^{
            // 更新界面
            
            if (!showProgress)
            {
                [progress removeFromSuperview];
                progress = nil;
            }
        });
    });
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败" title:@"注意"];
}
-(void)setBrandRequest:(NSString *)strManufacturerCodeeee//向太保移动平台发送请求报文
{
    [arrCarBrand removeAllObjects];
    [arrCarBrandCode removeAllObjects];
    
    WSqlite *sql =[WSqlite Instance];
    NSMutableArray *myArrData=[sql getBrand:strManufacturerCode];
    if ([strManufacturerCode isEqualToString:@"all"]) {
        [arrCarBrand removeAllObjects];
        [arrCarBrandCode removeAllObjects];
        return;
    }
    if ([myArrData count]>0) {
//        [arrCarBrand removeAllObjects];
//        [arrCarBrandCode removeAllObjects];
        for (int i=0; i<[myArrData count]; i++) {
            
            NSMutableDictionary *dictItem=[myArrData objectAtIndex:i];
            NSString *str=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"brandName"]];
            NSString *strCode=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"brandCode"]];
            [arrCarBrand addObject:str];
            [arrCarBrandCode addObject:strCode];
            [str release];
            [strCode release];
            
        }
    }
    else
    {
        if (ISNETVALID==YES) {
            
            NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
            [dicRequest setObject:@"admin22" forKey:@"userAccount"];
            [dicRequest setObject:strManufacturerCodeeee forKey:@"manufacturerCode"];
            NSString *strRequestJson=[dicRequest JSONRepresentation];
            ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
            
            //设置需要POST的数据，这里提交两个数据，A=a&B=b
            [request setPostValue:@"62012" forKey:@"RequestCode"];
            [request setPostValue:strRequestJson forKey:@"RequestData"];
            
            [request setDelegate:self];
            [request setDidFailSelector:@selector(ResponseBrandFail:)];
            [request setDidFinishSelector:@selector(ResonseBrandSuccess:)];
            [request startAsynchronous];
            
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                // 耗时的操作
                dispatch_async(dispatch_get_main_queue(), ^{
                    // 更新界面
                    
                    showProgress = YES;
                    if (showProgress) {
                        NSLog(@"88888");
                        //[NSThread sleepForTimeInterval:1];
                        progress= [[MBProgressHUD alloc]initWithView:self.navigationController.view];
                        [self.navigationController.view addSubview:progress];
                        [self.navigationController.view bringSubviewToFront:progress];
                        progress.labelText = @"查询中...";
                        [progress show:YES];
                        showProgress = NO;
                    };
                });
            });
            
        }
        else if(ISNETVALID==NO)
        {
            
        }
    }
    
}

- (void)ResonseBrandSuccess:(ASIHTTPRequest *)request
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 耗时的操作
        dispatch_async(dispatch_get_main_queue(), ^{
            // 更新界面
            
            if (!showProgress)
            {
                [progress removeFromSuperview];
                progress = nil;
            }
        });
    });
    [arrCarBrand removeAllObjects];
    [arrCarBrandCode removeAllObjects];
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse  %@",dictResponse);
    NSMutableArray *myArrData=[dictResponse valueForKey:@"datas"];
    if ([myArrData count]>0) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            // 耗时的操作
            if (strManufacturerCode.length!=0) {
                WSqlite *sql =[WSqlite Instance];
                [sql insertBrand:myArrData withManufacturerCode:strManufacturerCode];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                // 更新界面
            });
        });
    }
    for (int i=0; i<[myArrData count]; i++) {
        
        NSMutableDictionary *dictItem=[myArrData objectAtIndex:i];
        NSString *str=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"brandName"]];
        NSString *strCode=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"brandCode"]];
        [arrCarBrand addObject:str];
        [arrCarBrandCode addObject:strCode];
        [str release];
        [strCode release];

    }
    
}

- (void)ResponseBrandFail:(ASIHTTPRequest *)request
{
    [arrCarBrand removeAllObjects];
    [arrCarBrandCode removeAllObjects];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 耗时的操作
        dispatch_async(dispatch_get_main_queue(), ^{
            // 更新界面
            
            if (!showProgress)
            {
                [progress removeFromSuperview];
                progress = nil;
            }
        });
    });
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败" title:@"注意"];
}


#pragma UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (TableCar==YES) {
        return 3;
    }
    else if(TableCar==NO)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 30;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *Identifier=@"Identifier";
    UITableViewCell *cell=(UITableViewCell *)[TableViewMap dequeueReusableCellWithIdentifier:Identifier];

    if (cell==nil)
    {
        cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier]autorelease];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        cell.backgroundColor = [UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1.0f];
        
    }
    
    UIImage *image= [ UIImage imageNamed:@"login_type.png" ];
    UIButton *button = [ UIButton buttonWithType:UIButtonTypeCustom ];
    CGRect frame = CGRectMake( 25.0 , 5.0 , 20 , 20 );
    button. frame = frame;
    [button setBackgroundImage:image forState:UIControlStateNormal ];
    button. backgroundColor = [UIColor clearColor ];
    
    if (indexPath.row==0) {
        //cell.textLabel.text=@"服务网点类型";
        //lblServiceType.text=@"服务网点类型";
        [cell addSubview:lblServiceType];
        [button addTarget:self action:@selector(setServiceType:) forControlEvents:UIControlEventTouchDown];
        cell.accessoryView=button;
        
    }
    else if(indexPath.row==1)
    {
        //cell.textLabel.text=@"生产厂商";
        
        [cell addSubview:lblProduct];
        [button addTarget:self action:@selector(setManufacturer:) forControlEvents:UIControlEventTouchDown];
        cell.accessoryView=button;
    }
    else if(indexPath.row==2)
    {
        //cell.textLabel.text=@"车辆品牌";
        
        [cell addSubview:lblCarBrand];
        [button addTarget:self action:@selector(setCarType:) forControlEvents:UIControlEventTouchDown];
        cell.accessoryView=button;
    }
    
    return cell;
    
}

-(void)setServiceType:(id)sender
{
    
    [self setServiceTypeRequest];


}
-(void)setManufacturer:(id)sender
{
    [self setManufactureRequest];

}
-(void)setCarType:(id)sender
{
    if ([arrCarBrand count]==0) {
        [self justShowMessage:@"车辆品牌为空" title:@"注意"];
        return;
    }
    if ([strManufacturerCode isEqualToString:@"all"]) {
        [self justShowMessage:@"车辆品牌为空" title:@"注意"];
        return;
    }
    CustomActionSheet *sheet=[[CustomActionSheet alloc]initWithHeight:284.0f WithSheetTitle:@"" WithDataArray:arrCarBrand];
    sheet.tag=3;
    sheet.Customdelegate=self;
    [sheet showInView:self.view];
}
-(void)ClickItem:(NSString *)Title selectRow:(NSInteger )SelectRow ActionSheetTag:(NSInteger)actionSheetTag
{
    
    if (actionSheetTag==1) {
        NSString *strServiceName=[arrServiceName objectAtIndex:SelectRow];
        if (strServiceName.length!=0) {
             lblServiceType.text=[NSString stringWithFormat:@"服务网点类型:   %@",strServiceName];
        }
        else
        {
            lblServiceType.text=@"服务网点类型";
        }
        if ([arrServiceTypeCode objectAtIndex:SelectRow]) {
            strServiceType=[arrServiceTypeCode objectAtIndex:SelectRow];
        }
        else
        {
            strServiceType=@"";

        }
        if ([strServiceType isEqualToString:@"OT_1001"]) {
            TableCar=YES;
            [mamapView setFrame:CGRectMake(0, 138, 320, 470)];
        }
        else
        {
            TableCar=NO;
            [mamapView setFrame:CGRectMake(0, 78, 320, 470)];
        }
        lblProduct.text=@"生产厂商";
        lblCarBrand.text=@"车辆品牌";
        [TableViewMap reloadData];
        strCarBrandddd=@"";
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            // 耗时的操作
            if ([strServiceType isEqualToString:@"OT_1001"])
            {
                if (strBrandInvalid.length!=0)
                {
                    if ([strBrandInvalid isEqualToString:@"YN_1"])
                    {
                        [self getCarInfo];
                    }
                    else
                    {
                        [self setRequest];
                    }
                }
                else
                {
                    [self setRequest];
                }
            }
            else
            {
                [self setRequest];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                // 更新界面
            });  
        });
        
    }
    else if(actionSheetTag==2)
    {
        strManufacturerCode=[arrProductCode objectAtIndex:SelectRow];
        if ([strManufacturerCode isEqualToString:@"all"]) {
            [TableViewMap reloadData];
            lblProduct.text=@"生产厂商:所有";
            lblCarBrand.text=@"车辆品牌:";
            strCarBrandddd=@"";
            
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                // 耗时的操作
                [self setRequest];
                dispatch_async(dispatch_get_main_queue(), ^{
                    // 更新界面
                });  
            });
        }
        else
        {
            NSString *strManufactuer=[arrProduct objectAtIndex:SelectRow];
            if (strManufactuer.length!=0) {
                lblProduct.text=[NSString stringWithFormat:@"生产厂商:   %@",strManufactuer];
            }
            else
            {
                lblProduct.text=@"生产厂商";
            }
            lblCarBrand.text=@"车辆品牌";
            if (strManufacturerCode.length==0) {
                [self justShowMessage:@"生产厂商代码为空" title:@"注意"];
                return;
            }
            else
            {
                [self setBrandRequest:strManufacturerCode];
            }
        }
    }
    else if(actionSheetTag==3)
    {
        NSString *strCarBranddd=[arrCarBrand objectAtIndex:SelectRow];
        if (strCarBranddd.length!=0) {
            lblCarBrand.text=[NSString stringWithFormat:@"车辆品牌:   %@",strCarBranddd];
        }
        else
        {
            lblCarBrand.text=@"车俩品牌";
        }
        strCarBrandddd=[arrCarBrandCode objectAtIndex:SelectRow];
        [self setRequest];
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIButton *button = [ UIButton buttonWithType:UIButtonTypeCustom ];
    if (indexPath.row==0) {
        [self setServiceType:button];
    }
    else if(indexPath.row==1)
    {
        [self setManufacturer:button];
    }
    else if(indexPath.row==2)
    {
        if ([strManufacturerCode isEqualToString:@"all"]) {
            [self justShowMessage:@"车辆品牌为空" title:@"注意"];
            return;
        }
        [self setCarType:button];
    }
}
-(void) ClickCallOutBtn
{
    if ([Flag isEqualToString:@"0"])
    {
        [self IFServiceEvaluation];
        Flag = @"1";
    }
    else
    {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}

-(void)setEvaluationRequest
{
    NSLog(@"==================");
    NSString *serviceid =@"50101";
    NSString *servicename =@"服务网点查询";
    IFServiceEvaluation *ifserviceevaluation =[[IFServiceEvaluation alloc]initView:serviceid withserviceName:servicename];
    [ifserviceevaluation setIfServiceEvaluationRequest];
    [ifserviceevaluation setHidden:YES];
    [self.view addSubview:ifserviceevaluation];
    [ifserviceevaluation release];
}
-(void) IFServiceEvaluation
{
    NSString *serviceid =@"50101";
    NSString *servicename =@"服务网点查询";
    NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil) {
        if ([dictUserInfo valueForKey:@"UserAccount"]) {
            if ([myDefaults stringForKey:serviceid]) {
                NSString *strEvaluate=[myDefaults stringForKey:serviceid];
                if ([strEvaluate isEqualToString:@"1"]) {
                    AddServiceEvaluationViewController *serviceevluation = [[AddServiceEvaluationViewController alloc]initView:serviceid withserviceName:servicename];
                    [[AppDelegate app].unc pushViewController:serviceevluation animated:YES];
                    [serviceevluation release];
                }
                else
                {
                    [self.navigationController popToRootViewControllerAnimated:YES];
                }
            }
            else
            {
                [self.navigationController popToRootViewControllerAnimated:YES];
            }
        }
    }
    else
    {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }

}

-(void)viewWillAppear:(BOOL)animated{
    [annotions removeAllObjects];
    
    if(isLocation){
        MACoordinateSpan span;
        span.latitudeDelta=0.3;
        span.longitudeDelta=0.2;
        MACoordinateRegion rrr;
        rrr.center=location1;
        rrr.span=span;
        [mamapView setRegion:rrr animated:NO];
        [mamapView setCenterCoordinate:location1];
        //[self addAnnotion];
    }
    else
    {
        CLLocationCoordinate2D locationSZ;
        locationSZ.latitude=22.543099;
        locationSZ.longitude=114.05786799999998;
        MACoordinateSpan span;
        span.latitudeDelta=0.3;
        span.longitudeDelta=0.2;
        MACoordinateRegion rrr;
        rrr.center=location1;
        rrr.span=span;
        [mamapView setRegion:rrr animated:NO];//设定当前地图的显示范围
        [mamapView setCenterCoordinate:locationSZ];//设定地图中心点坐标
    }
    [super viewWillAppear:animated];
}
-(void)viewWillDisappear:(BOOL)animated{
    [mamapView removeAnnotations:annotions];
}

- (MAAnnotationView*)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation{
    if([annotation isKindOfClass:[MAUserLocation class]]){
        NSString *reuseIdentifier = @"annuserlocation";
        MAAnnotationView *annotationView=[[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
        [annotationView setCanShowCallout:YES];
        [annotationView setCenterOffset:CGPointMake(7, 34.5)];
        [annotationView setEnabled:NO];
        
        [annotationView setDraggable:YES];
        NSLog(@"return viewForAnnotation----MAMapkitTestAnnotation");
        return  annotationView;
        
    }
    else if([annotation isKindOfClass:[MAPointAnnotation class]])
    {
        MYPoint *myPoint=(MYPoint *)annotation;
        //NSString *strPoint=[[NSString alloc]initWithFormat:@"touch %d",myPoint.tag];
        //[self justShowMessage:strPoint title:nil];
        MAPinAnnotationView *pinAnnView = [[[MAPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"pinAnnView"]autorelease];
        pinAnnView.tag=myPoint.tag;
        NSLog(@"annotation:%f,%f",annotation.coordinate.latitude,annotation.coordinate.longitude);
        pinAnnView.pinColor = MAPinAnnotationColorRed;
        pinAnnView.animatesDrop = YES;
        pinAnnView.canShowCallout = YES;
        pinAnnView.draggable = YES;
        

        //pinAnnView.leftCalloutAccessoryView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"qqLogin.png"]];
        UIButton *selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [selectButton setFrame:(CGRect){0,0,50,40}];
        [selectButton setTitle:@"确定" forState:UIControlStateNormal];
        //pinAnnView.rightCalloutAccessoryView =selectButton;//气泡框右侧显示的View 可自定义
        [selectButton setBackgroundColor:[UIColor redColor]];
        [selectButton setShowsTouchWhenHighlighted:YES];
        [selectButton addTarget:self action:@selector(gotoURL) forControlEvents:UIControlEventTouchUpInside];
        
        
        NSMutableDictionary *dictItem=[arrData objectAtIndex:myPoint.tag];
        NSString *strExponent=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"exponent"]];
        strExponent=[strExponent substringFromIndex:3];
        NSString *strExpoentTag;
        if([strExponent isEqualToString:@"1"])
        {
            strExpoentTag=[[NSString alloc]initWithFormat:@"%@",@"★"];
        }
        else if([strExponent isEqualToString:@"2"])
        {
            strExpoentTag=[[NSString alloc]initWithFormat:@"%@",@"★★"];
        }
        else if([strExponent isEqualToString:@"3"])
        {
            strExpoentTag=[[NSString alloc]initWithFormat:@"%@",@"★★★"];
        }
        else if([strExponent isEqualToString:@"4"])
        {
            strExpoentTag=[[NSString alloc]initWithFormat:@"%@",@"★★★★"];
        }
        else if([strExponent isEqualToString:@"5"])
        {
            strExpoentTag=[[NSString alloc]initWithFormat:@"%@",@"★★★★★"];
        }
        else
        {
            strExpoentTag=[[NSString alloc]initWithFormat:@"%@",@""];
        }
        
        NSString *strName=[dictItem valueForKey:@"name"];
        if (strName.length>13) {
            strName=[strName substringToIndex:11];
        }
        
        NSString *Title1=[[NSString alloc]initWithFormat:@"%@          推荐指数%@",strName,strExpoentTag];
        NSString *strSupport=[[NSString alloc]initWithFormat:@"服务内容:%@",[dictItem valueForKey:@"support"]];
        NSString *strPromotions;
        if ([dictItem valueForKey:@"promotions"]) {
            strPromotions=[[NSString alloc]initWithFormat:@"优惠信息:%@",[dictItem valueForKey:@"promotions"]];
        }else
        {
             strPromotions=[[NSString alloc]initWithFormat:@"优惠信息:%@",@""];
        }
        
        NSString *strAddress=[[NSString alloc]initWithFormat:@"联系地址:%@",[dictItem valueForKey:@"address"]];
        NSString *strPhoneNo=[[NSString alloc]initWithFormat:@"联系电话:%@",[dictItem valueForKey:@"phoneNo"]];
        [txwContentDetail setText:[dictItem valueForKey:@"support"]];
        NSString *strCotent=[[NSString alloc]initWithFormat:@"服务:%@,优惠:%@,联系:%@",strSupport,strPromotions,strAddress];
        [txwContentDetail setText:strCotent];
        strURLLLLLL=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"promotions"]];
        strPhoneeeee=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"phoneNo"]];
//        strid=[dictItem valueForKey:@"id"];

        UILabel *labelTitle=[[UILabel alloc]initWithFrame:CGRectMake(5, 0, 350, 25)];
        labelTitle.backgroundColor=[UIColor clearColor];
        labelTitle.font=[UIFont boldSystemFontOfSize:14.0];
        labelTitle.textColor=[UIColor whiteColor];
        labelTitle.text=Title1;
        NSInteger LabelHeight=0;
        if ([dictItem valueForKey:@"support"]) {
            LabelHeight=LabelHeight+20;
        }
        UILabel *labelSupport=[[UILabel alloc]initWithFrame:CGRectMake(5, LabelHeight, 350, 20)];
        labelSupport.backgroundColor=[UIColor clearColor];
        labelSupport.font=[UIFont systemFontOfSize:13.0];
        labelSupport.textColor=[UIColor whiteColor];
        labelSupport.text=strSupport;
        UIButton *btnPromotions = [UIButton buttonWithType:UIButtonTypeCustom];
        if ([dictItem valueForKey:@"promotions"]) {
            NSString *strPro=[dictItem valueForKey:@"promotions"];
            if (strPro.length!=0) {
                 LabelHeight=LabelHeight+20;
            }
        }
        [btnPromotions setFrame:(CGRect){0,LabelHeight,350,20}];
        btnPromotions.backgroundColor=[UIColor clearColor];
        btnPromotions.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        btnPromotions.titleLabel.textAlignment=UITextAlignmentLeft;
        btnPromotions.contentEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        btnPromotions.titleLabel.font=[UIFont systemFontOfSize:13.0];
        btnPromotions.titleLabel.textColor=[UIColor blueColor];
        [btnPromotions setTitle:strPromotions forState:UIControlStateNormal];
        [btnPromotions setShowsTouchWhenHighlighted:YES];
        btnPromotions.tag=myPoint.tag;
        [btnPromotions addTarget:self action:@selector(gotoURL:) forControlEvents:UIControlEventTouchUpInside];
        UIImageView *imgline = [[UIImageView alloc]initWithFrame:CGRectMake(50,LabelHeight+18,120,1)];
        imgline.backgroundColor = [UIColor whiteColor];
        
        
        UIButton *btnAddress = [UIButton buttonWithType:UIButtonTypeCustom];
        if ([dictItem valueForKey:@"address"]) {
            LabelHeight=LabelHeight+20;
        }
        [btnAddress setFrame:(CGRect){0,LabelHeight,350,20}];
        btnAddress.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        btnAddress.titleLabel.textAlignment=UITextAlignmentLeft;
        btnAddress.contentEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        btnAddress.backgroundColor=[UIColor clearColor];
        btnAddress.titleLabel.font=[UIFont systemFontOfSize:13.0];
        [btnAddress setTitle:strAddress forState:UIControlStateNormal];
        
        UIButton *btnPhoneNo = [UIButton buttonWithType:UIButtonTypeCustom];
        if ([dictItem valueForKey:@"phoneNo"]) {
            LabelHeight=LabelHeight+20;
        }
        [btnPhoneNo setFrame:(CGRect){0,LabelHeight,350,20}];
        btnPhoneNo.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        btnPhoneNo.titleLabel.textAlignment=UITextAlignmentLeft;
        btnPhoneNo.contentEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        btnPhoneNo.backgroundColor=[UIColor clearColor];
        btnPhoneNo.titleLabel.font=[UIFont systemFontOfSize:13.0];
        btnPhoneNo.titleLabel.textColor=[UIColor blueColor];
        [btnPhoneNo setTitle:strPhoneNo forState:UIControlStateNormal];
        [btnPhoneNo setShowsTouchWhenHighlighted:YES];
        btnPhoneNo.tag=myPoint.tag;
        [btnPhoneNo addTarget:self action:@selector(sendPhoneno:) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *btnPreferential = [UIButton buttonWithType:UIButtonTypeCustom];
        [btnPreferential setFrame:(CGRect){0,103,350,20}];
        btnPreferential.backgroundColor=[UIColor clearColor];
        btnPreferential.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        btnPreferential.titleLabel.textAlignment=UITextAlignmentLeft;
        btnPreferential.contentEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        btnPreferential.titleLabel.font=[UIFont boldSystemFontOfSize:13.0];
        [btnPreferential setTitleColor:[UIColor redColor]forState:UIControlStateNormal];
        [btnPreferential setTitle:@"本地优惠信息" forState:UIControlStateNormal];
        [btnPreferential setShowsTouchWhenHighlighted:YES];
        btnPreferential.tag=myPoint.tag;
        [btnPreferential addTarget:self action:@selector(gotoPreferential:) forControlEvents:UIControlEventTouchUpInside];

        
        UIView *viewDetail=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 350, 130)];
        
        [viewDetail addSubview:labelTitle];
        if ([dictItem valueForKey:@"support"]) {
            [viewDetail addSubview:labelSupport];
        }
        if ([dictItem valueForKey:@"promotions"])
        {
            NSString *strPro=[dictItem valueForKey:@"promotions"];
            if (strPro.length!=0) {
                [viewDetail addSubview:btnPromotions];
            }
            
        }
        [viewDetail addSubview:btnAddress];
        if ([dictItem valueForKey:@"promotions"])
        {
            NSString *strPro=[dictItem valueForKey:@"promotions"];
            if (strPro.length!=0) {
                [viewDetail addSubview:imgline];
            }
        }
        if ([dictItem valueForKey:@"address"])
        {
            [viewDetail addSubview:btnAddress];
        }
        if ([dictItem valueForKey:@"phoneNo"]) {
            [viewDetail addSubview:btnPhoneNo];
        }
        
        if (ISNETVALID==YES)
        {
            [viewDetail addSubview:btnPreferential];
        }
        
        pinAnnView.leftCalloutAccessoryView=viewDetail;
        
        return pinAnnView;
    }
    else
    {
        MAAnnotationView *annotationView=[[[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
        //MAPointAnnotation *placeMark=(MAPointAnnotation *)annotation;
        
        [annotationView setCanShowCallout:YES];
        [annotationView setCenterOffset:CGPointMake(7, 34.5)];
        [annotationView setEnabled:YES];
        
        [annotationView setDraggable:YES];
        NSLog(@"return viewForAnnotation----MAMapkitTestAnnotation");
        return  annotationView;
    }
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
-(void)dealloc{
    mamapView.showsUserLocation=NO;
    mamapView.delegate=nil;
    [arrProduct release];
    [arrProductCode release];
    [arrCarBrandCode release];
    [arrCarBrand release];
    [arrServiceTypeAnotion release];
    [arrServiceTypeCode release];
    [arrServiceName release];
    [mamapView release];
    [annotions release];
    [lblCarBrand release];
    [lblProduct release];
    [lblServiceType release];
    
    if(requestServerType)
    {
        [requestServerType clearDelegatesAndCancel];
        requestServerType=nil;
    }
    [super dealloc];
}
- (void)mapViewWillStartLocatingUser:(MAMapView *)mapView NS_AVAILABLE(NA, 4_0){
    
    NSLog(@"++++startLocation");
}

/**
 *在地图View停止定位后，会调用此函数
 *@param mapView 地图View
 */
- (void)mapViewDidStopLocatingUser:(MAMapView *)mapView NS_AVAILABLE(NA, 4_0){
    NSLog(@"++++++++stopLocation");
    //[self addAnnotion];
}

/**
 *用户位置更新后，会调用此函数
 *@param mapView 地图View
 *@param userLocation 新的用户位置
 */
- (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation NS_AVAILABLE(NA, 4_0){
    NSLog(@"++++++successLocation");
    NSLog(@"+++++++++++++%f+++++++++%f+++=",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
    CLLocationCoordinate2D location=userLocation.location.coordinate;
    location1=userLocation.location.coordinate;
    MACoordinateSpan span;
    span.latitudeDelta=0.03;//地图精度,精度越小,显示的位置越准确
    span.longitudeDelta=0.02;//地图精度,精度越小,显示的位置越准确
    
    MACoordinateRegion rrr;
    rrr.center=location;
    rrr.span=span;
    [mamapView setRegion:rrr animated:NO];
    [mamapView setCenterCoordinate:location];
    
    
    [mamapView setShowsUserLocation:NO];
    isLocation=YES;
    
}

/**
 *定位失败后，会调用此函数
 *@param mapView 地图View
 *@param error 错误号，参考CLError.h中定义的错误号
 */
- (void)mapView:(MAMapView *)mapView didFailToLocateUserWithError:(NSError *)error NS_AVAILABLE(NA, 4_0)
{
    NSLog(@"+++++++++++++failLocation");
    mamapView.showsUserLocation=NO;
    isLocation=NO;
    CLLocationCoordinate2D locationSZ;
    locationSZ.latitude=22.543099;
    locationSZ.longitude=114.05786799999998;
    MACoordinateSpan span;
    span.latitudeDelta=0.3;
    span.longitudeDelta=0.2;
    MACoordinateRegion rrr;
    rrr.center=location1;
    rrr.span=span;
    [mamapView setRegion:rrr animated:NO];//设定当前地图的显示范围
    [mamapView setCenterCoordinate:locationSZ];//设定地图中心点坐标
}
/**
 *当mapView新添加annotation views时，调用此接口
 *@param mapView 地图View
 *@param views 新添加的annotation views
 */
- (void)mapView:(MAMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    //[self justShowMessage:@"didAddAnnotationViews" title:nil];
}

/**
 *当选中一个annotation views时，调用此接口
 *@param mapView 地图View
 *@param views 选中的annotation views
 */
- (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view NS_AVAILABLE(NA, 4_0)
{

}

/**
 *当取消选中一个annotation views时，调用此接口
 *@param mapView 地图View
 *@param views 取消选中的annotation views
 */
- (void)mapView:(MAMapView *)mapView didDeselectAnnotationView:(MAAnnotationView *)view NS_AVAILABLE(NA, 4_0)
{
//    [AnotionViewDetail removeFromSuperview];
}

/**
 *地图区域即将改变时会调用此接口
 *@param mapview 地图View
 *@param animated 是否动画
 */
- (void)mapView:(MAMapView *)mapView regionWillChangeAnimated:(BOOL)animated
{
//    [AnotionViewDetail removeFromSuperview];
}

/**
 *地图区域改变完成后会调用此接口
 *@param mapview 地图View
 *@param animated 是否动画
 */
- (void)mapView:(MAMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    
}

/**
 *拖动annotation view时view的状态变化，ios3.2以后支持
 *@param mapView 地图View
 *@param view annotation view
 *@param newState 新状态
 *@param oldState 旧状态
 */
- (void)mapView:(MAMapView *)mapView annotationView:(MAAnnotationView *)view didChangeDragState:(MAAnnotationViewDragState)newState
fromOldState:(MAAnnotationViewDragState)oldState NS_AVAILABLE(NA, 4_0)
{
    
}


-(NSString*)keyForMap
{
    return @"c14816a5330213770ea772273a41bc24";//高德地图key
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
